package com.facebook.drawee.drawable;

import android.graphics.drawable.Drawable;

public class DrawableUtils {
    public static void setCallbacks(Drawable drawable, Drawable.Callback callback, TransformCallback transformCallback) {
        if (drawable != null) {
            drawable.setCallback(callback);
            if ((drawable instanceof TransformAwareDrawable)) {
                ((TransformAwareDrawable) drawable).setTransformCallback(transformCallback);
            }
        }
    }

    public static void setDrawableProperties(Drawable drawable, DrawableProperties drawableProperties) {
        boolean v1 = true;
        int v3 = -1;
        if (drawable != null && drawableProperties != null && drawable != null) {
            if (drawableProperties.alpha != v3) {
                drawable.setAlpha(drawableProperties.alpha);
            }

            if (drawableProperties.b) {
                drawable.setColorFilter(drawableProperties.c);
            }

            if (drawableProperties.d != v3) {
                boolean v0 = drawableProperties.d != 0 ? true : false;
                drawable.setDither(v0);
            }

            if (drawableProperties.e == v3) {
                return;
            }

            if (drawableProperties.e == 0) {
                v1 = false;
            }

            drawable.setFilterBitmap(v1);
        }
    }

    public static int multiplyColorAlpha(int color, int alpha) {
        if (alpha == 255) {
            return color;
        }
        if (alpha == 0) {
            return color & 0x00FFFFFF;
        } else {
            return ((alpha >> 7) + alpha) * (color >>> 24) >> 8 << 24 | color & 0x00FFFFFF;
        }
    }
}
